package com.example.bookstore.utils;

import com.example.bookstore.model.MyPage;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

import java.util.HashMap;
import java.util.List;

public class PageUtil {

    public static HashMap<String,Object> getMap(List<?> t){

        MyPage myPage = new MyPage();
        HashMap<String,Object> hashMap = new HashMap<>();
        PageHelper.startPage(myPage.getPage(),myPage.getRow());
        PageInfo<?> PageInfo = new PageInfo<>(t);
        hashMap.put("list",PageInfo.getList());
        hashMap.put("total",PageInfo.getTotal()); //总条数
        hashMap.put("totalPage",PageInfo.getPages()); //总页数

        if(PageInfo.getPrePage() == 0) {
            hashMap.put("pre",1);
        }else {
            hashMap.put("pre",PageInfo.getPrePage());
        }

        if(PageInfo.getNextPage() == 0){
            hashMap.put("next",PageInfo.getPages());
        }else {
            hashMap.put("next",PageInfo.getNextPage());
        }

        hashMap.put("cur",PageInfo.getPageNum());

        return hashMap;
    }
}
